package com.haifeng.lyw.jinganghc.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.haifeng.lyw.jinganghc.R;
import com.haifeng.lyw.jinganghc.dao.UserDao;
import com.haifeng.lyw.jinganghc.dao.UserInfo;

public class UpActivity extends Activity implements View.OnClickListener{
    private String[] wrestle_action = {"跳绳", "前走一步", "后走一步", "鞠躬"};
    private String[] wrestle_action_order= {"Z", "k", "m", "R",};
    private String[] soccer_action = {"扑球", "投球", "敲鼓", "直立阻挡"};
    private String[] soccer_action_order= {"z", "K", "M", "P"};
    private Spinner sp_action;
    private int position;
    private String[] action_data;
    private String[] action_data_order;
private String actionKey;
    private TextView up_ok;
private ArrayAdapter adapter;
    private String actionType;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_up);

        Intent intent = getIntent();
        position = intent.getIntExtra("position",0);


      initView();

    }

    private void initView() {
        sp_action=(Spinner) findViewById(R.id.sp_action);
        up_ok=findViewById(R.id.up_ok);
        up_ok.setOnClickListener(this);
        if(position<5){
            adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, wrestle_action);
            action_data=wrestle_action;
            action_data_order=wrestle_action_order;
            sp_action.setAdapter(adapter );
            actionKey="格斗键"+(position+1);
            actionType="格斗";

        }else{
            adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, soccer_action);
            action_data=soccer_action;
            action_data_order=soccer_action_order;
            sp_action.setAdapter(adapter );
            actionKey="踢球键"+(position-4);
            actionType="踢球";

        }
        adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    }
    /**
     * 修改
     */
    private void reData() {


            UserInfo userInfo = new UserInfo();
            userInfo.setId((long) (position+1));
            userInfo.setName(actionKey);
            userInfo.setType(actionType);
            userInfo.setAction(action_data[sp_action.getSelectedItemPosition()]);
        userInfo.setAction_order(action_data_order[sp_action.getSelectedItemPosition()]);

            UserDao.getInstance().ReplaceData(userInfo);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.up_ok:
                reData();
                finish();
                break;
        }
    }
}
